
DECLARE
VN_COUNT     NUMBER;
v_SQL        VARCHAR2(4000);
BEGIN
<#if tableList??&&(tableList?size>0)>
    <#list tableList as t>
        <#if t.tableColumns??&&(t.tableColumns?size>0)>
            <#list t.tableColumns as column>
                begin
                select COUNT(*) INTO VN_COUNT from USER_TAB_COLUMNS where table_name = '${t.name}' AND COLUMN_NAME = '${column.columnName}';
                IF VN_COUNT < 1 THEN
                v_SQL := ' alter table ${t.name} add (${column.columnName} ${column.columnOracleType()} '||
                <#if column.columnLength??&&column.columnLength!="">
                    ' (${column.columnLength} '||
                </#if>
                <#if column.columnPrecision??&&column.columnPrecision!="">
                    ' ,${column.columnPrecision}) '||
                <#elseif column.columnLength??&&column.columnLength!="" >
                    ' ) '||
                </#if>
                <#if column.columnDefault??&&column.columnDefault!="">
                    ' default ${column.columnDefault} '||
                </#if>
                <#if column.getNullable()>
                    ' NOT NULL '||
                </#if>
                ' ) ';
                EXECUTE IMMEDIATE V_STR;
                DBMS_OUTPUT.PUT_LINE('${column.columnName} 字段新建成功');
                <#if column.columnAnnotation??&&column.columnAnnotation!="">
                    EXECUTE IMMEDIATE 'COMMENT ON COLUMN ${t.name}.${column.columnName} IS ''${column.columnAnnotation}''';
                </#if>
                ELSE
                DBMS_OUTPUT.PUT_LINE('${column.columnName} 字段已存在');
                END IF;
                exception when  others then
                dbms_output.put_line('错误号：'||sqlcode);
                dbms_output.put_line('错误信息：'||sqlerrm);
                END;
            </#list>
        </#if>

    </#list>
</#if>

END;